home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / mh / contrib / audit / mh.pl < prev    next >
Text File  |  1992-11-19  |  4KB  |  189 lines

  1.  
  2.  
  3. # =====
  4. # Subroutine mh_profile
  5. #    Parse the user's .mh_profile and get arguments and settings
  6. #
  7. sub mh_profile {
  8.     local($PROFILE);
  9.  
  10.     ($PROFILE = $ENV{"MH"}) || ($PROFILE = $ENV{"HOME"} . "/.mh_profile");
  11.  
  12.     open PROFILE || "$0: can't read mh_profile $PROFILE: $!\n";
  13.  
  14.     while (<PROFILE>) {
  15.     next if /^#/;
  16.     next unless ($key, $value) = /([^:\s]+):\s*(.+)/;
  17.     $key =~ tr/A-Z/a-z/;
  18.     $MH{$key} = $value;
  19.     } 
  20.     close PROFILE;
  21.  
  22.     $MH{'path'} = $ENV{'HOME'} . '/' . $MH{'path'};
  23.  
  24.  
  25. # =====
  26. # Subroutine rcvstore
  27. #    Convenience routine for MH users. Pipes incoming
  28. #    mail message to rcvstore. Expects one argument - the 
  29. #    name of the folder to rcvstore into.
  30. #
  31. sub rcvstore {
  32.     local($folder) = @_;
  33.  
  34.     &openpipe("/usr/local/bin/mh/lib/rcvstore +$folder -create");
  35. }
  36.  
  37.  
  38. # =====
  39. # Subroutine rcvdist
  40. #    Convenience routine for MH users. Pipes incoming
  41. #    mail message to rcvdist. Expects one argument - the 
  42. #    list of users to distribute the mail message to
  43. #
  44. sub rcvdist {
  45.     local($recips) = @_;
  46.  
  47.     &openpipe("/usr/local/bin/mh/lib/rcvdist $recips");
  48. }
  49.  
  50.  
  51. # =====
  52. # Subroutine rcvtty
  53. #    Convenience routine for MH users. Pipes incoming
  54. #    mail message to rcvtty. This is MH's version of biff.
  55. #
  56. sub rcvtty {
  57.  
  58.     &openpipe("/usr/local/bin/mh/lib/rcvtty");
  59. }
  60.  
  61.  
  62. # =====
  63. # Subroutine ali
  64. #       Expand an MH alias into a list of names usable by
  65. #       rcvdist
  66. #
  67. sub ali {
  68.     local($alias) = @_;
  69.     local($recips); 
  70.     local(@list) = ();
  71.  
  72.     $recips = `/usr/local/bin/mh/ali $alias`;
  73.     chop $recips;
  74.     return(@list) if ($alias eq $recips);
  75.  
  76.     @list = split(/,/, $recips);
  77.     return(@list);
  78. }
  79.  
  80.  
  81. # =====
  82. # Subroutine refile_from
  83. #    Refile a message into a folder by organization and 
  84. #    sender name. The top-level folder is an argument
  85. #    the user can specify.
  86. #
  87. sub refile_from {
  88.     local($toplevel) = @_;
  89.  
  90.     return if (length($from) <= 0);
  91.     return if ($from eq $user);
  92.  
  93.     $toplevel = "log" if ($toplevel eq '');
  94.     &rcvstore("$toplevel/$organization/$from");
  95. }
  96.  
  97. # =====
  98. # Subroutine make_mhpath
  99. #    Make a directory path recursively. 
  100. #
  101. sub make_mhpath {
  102.     local($dir) = @_;
  103.     local($i);
  104.     local($mode) = 0755;
  105.  
  106.     $mode = oct($MH{'folder-protect'}) if (defined $MH{'folder-protect'});
  107.  
  108.     $_ = $dir;
  109.     s#^/.*#/# || s#^[^/].*#.#;
  110.     $start = $_;
  111.     foreach $i (split('/', $dir)) {
  112.     $start = $start . '/' . $i;
  113.     next if (-d $start);
  114.     mkdir($start, $mode) || return(1);
  115.     };
  116.  
  117.     return(0);
  118.  
  119.  
  120. # =====
  121. # Subroutine mh_parse
  122. #    Parse the command line options
  123. #
  124. sub mh_parse {
  125.     local(@argdesc) =  @SW;
  126.     local($wantarg);
  127.  
  128.     while (($#ARGV >= 0) && ($ARGV[0] !~ /^-.+/)) { # must be a message list
  129.     push(@MSGS, shift @ARGV);
  130.     };
  131.  
  132.     grep(s/(\W)/\\$1/g, @argdesc);
  133.  
  134.     @ARGV = (split(' ', $MH{$program}), @ARGV) if defined($MH{$program});
  135.  
  136.     return if ($#ARGV < 0);
  137.  
  138.     while ($ARGV[0] =~ /^-.+/) {
  139.  
  140.         $ARGV = shift @ARGV;
  141.  
  142.         unless (@matches = grep(/$ARGV/, @argdesc)) {
  143.             print "$program: unknown option: $ARGV\n";
  144.             exit 1;
  145.             &usage;
  146.         } 
  147.  
  148.         for (@matches) { s/\\(\W)/$1/g; } 
  149.  
  150.         if ($#matches > $[) {
  151.             print "$program: ambiguous switch $ARGV matches:\n";
  152.             for (@matches) { 
  153.                 print "\    ", $_, "\n"; 
  154.             }
  155.             exit 1;
  156.         } 
  157.  
  158.         ($switch,$wantarg) = $matches[$[] =~ /^-(\S+)\s*(\S*)/;
  159.  
  160.         $SW{$switch} = $wantarg ? shift @ARGV : 1;
  161.         if ($SW{$switch} =~ /^(['"]).*$/ && $SW{$switch} !~ /^(['"]).*\1$/) {
  162.             do {
  163.                 $SW{$switch} .= ' ' . (shift @ARGV);
  164.             } until $#ARGV < 0 || $SW{$switch} =~ /^(['"]).*\1$/;
  165.             $SW{$switch} =~ s/^(['"])(.*)\1$/$2/;
  166.         } 
  167.     }
  168. }
  169.  
  170.  
  171. # =====
  172. # Subroutine print_switches
  173. #    print the valid command line switches
  174. #
  175. sub print_switches {
  176.     local(@argdesc) = @SW;
  177.  
  178.     print "   switches are:\n";
  179.     for (sort @SW) {
  180.     print "   $_\n";
  181.     };
  182.     print "\n";
  183. }
  184.  
  185.  
  186. 1;
  187.